﻿////////////////////////////////////////////////////////////////////////////////
// Source Copyright (C) J.Fan
// @author      J.Fan
// @date        2013-02-08
// @revision    Revision in Version Control System
// @remark      
////////////////////////////////////////////////////////////////////////////////

using JsonConverter.Writer;

namespace JsonConverter.Converter
{
    public abstract class JavaScriptArrayConverter: IObjectConverter
    {
        protected JsonWriter Writer;

        public virtual void Convert(JsonWriter writer, object obj)
        {
            this.Writer = writer;

            BeginArray();
            OnConvertArray(obj);
            EndArray();
        }

        protected abstract void OnConvertArray(object obj);

        private void BeginArray()
        {
            Writer.WriteLiteral("[");
        }

        private void EndArray()
        {
            Writer.WriteLiteral("]");
        }
    }
}
